﻿using System.IO;
using System.Text;

namespace Z.IconLibraryGenerator.WinForm
{
    public partial class IconLibraryGeneratorManager
    {
        public static string GetEmbeddedText(ProjectConfiguration project)
        {
            var sb = new StringBuilder();

            foreach (var item in project.Icons)
            {
                sb.Append(GetEmbeddedText(project, item));
            }

            return sb.ToString();
        }

        public static string GetEmbeddedText(ProjectConfiguration project, ProjectIcon config)
        {
            const string template = "[assembly: WebResource(\"@(Model.Namespace).@(Model.IconSize).@(Model.FileName)\", \"image/png\")]";
            var sb = new StringBuilder();

            foreach (FileInfo file in config.Path.ToDirectoryInfo().GetFiles())
            {
                string s = template;
                s = s.Replace("@(Model.IconSize)", config.Prefix);
                s = s.Replace("@(Model.Namespace)", project.ProjectNamespace);
                s = s.Replace("@(Model.FileName)", file.Name);

                sb.AppendLine(s);
            }
            return sb.ToString();
        }
    }
}